
//
//  BookHomeworkTitleCell.m
//  TeacherPro
//
//  Created by DCQ on 2017/9/7.
//  Copyright © 2017年 ZNXZ. All rights reserved.
//

#import "BookHomeworkTitleCell.h"
#import "PublicDocuments.h"
#import "BookPreviewModel.h"
#import "UIImageView+WebCache.h"
#import "ProUtils.h"

@interface BookHomeworkTitleCell()
@property (weak, nonatomic) IBOutlet UIImageView *bookImgV;
@property (weak, nonatomic) IBOutlet UILabel *bookName;
@property (weak, nonatomic) IBOutlet UILabel *bookType;
 
@property (weak, nonatomic) IBOutlet UIButton *changeBookBtn;
@property (weak, nonatomic) IBOutlet UIImageView *bookUnitIconImgV;
@property (weak, nonatomic) IBOutlet UIImageView *bookTypeImgV;

@property (weak, nonatomic) IBOutlet UILabel *gameLabel;

@end
@implementation BookHomeworkTitleCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [self setupSubview];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)setupSubview{
    
    self.bookImgV.layer.shadowOpacity = 0.4;// 阴影透明度
    
    self.bookImgV.layer.shadowColor = [UIColor grayColor].CGColor;// 阴影的颜色
    
    self.bookImgV.layer.shadowRadius = 5;// 阴影扩散的范围控制
    
    self.bookImgV.layer.shadowOffset  = CGSizeMake(1, 1);// 阴影的范围
    self.bookName.textColor = UIColorFromRGB(0x6b6b6b);
    self.bookName.font = fontSize_14;
    self.bookType.textColor = UIColorFromRGB(0x9f9f9f);
    self.bookType.font = fontSize_14;
    [ProUtils setupButtonContent:self.changeBookBtn withType:ButtonContentType_imageRight];
     self.gameLabel.font = fontSize_13;
}

-(void)setupPreviewDetailInfo:(BookPreviewDetailModel *)detailModel{
    
    UIImage * placeholderImg = [UIImage imageNamed:BooksPlaceholderImgName];
    
    self.bookName.text = detailModel.name;
    if (detailModel) {
         self.bookType.text = [NSString stringWithFormat:@"%@/%@",detailModel.subjectName,detailModel.bookTypeName];
    }else{
        
        self.bookType.text = @"";
    }
        
   
    [self.bookImgV sd_setImageWithURL:[NSURL URLWithString:detailModel.coverImage] placeholderImage:placeholderImg];
    
    NSString * imageNameIcon = @"";
    NSString * unitIconImgName = @"";
    if ([detailModel.bookType  isEqualToString:@"Book"]) {
        imageNameIcon = @"homework_book_icon.png";
        
        for (PracticeTypeModel * typeModel in detailModel.practiceTypes) {
            if(typeModel.practiceType && [typeModel.practiceType isEqualToString:@"zxlx"]){
                unitIconImgName = @"homework_game_icon.png";
                self.gameLabel.hidden = NO;
            }
        }
      
    }else if ([detailModel.bookType isEqualToString:@"Cartoon"]){
        imageNameIcon = @"homework_cartoon_icon.png";
    }else{
        
        imageNameIcon = @"homework_assistants_icon.png";
    }
    
    self.bookTypeImgV.image = [UIImage imageNamed: imageNameIcon];
    self.bookUnitIconImgV.image = [UIImage imageNamed:unitIconImgName];
}
- (IBAction)changeBookAction:(id)sender {
 
    if (self.changeBookBlock) {
        self.changeBookBlock();
    }

}

@end
